<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>View Role Detail</title>
<link rel="stylesheet" type="text/css" href="../../themes/general.css">
<link rel="stylesheet" type="text/css" href="../../themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="../../themes/default/easyui.css">
<script type="text/javascript" src="../../scripts/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="../../scripts/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../../scripts/src/jquery.parser.js"></script>
<script type="text/javascript"
	src="../../scripts/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../../scripts/general.js"></script>
<script type="text/javascript" src="../../scripts/sessionExpriation.js"></script>
<script type="text/javascript">
	$(function() {
		var roleId = $.getUrlParam('roleId');

		var newRoleId = roleId;
		var updateCase = $.getUrlParam('updateCase');
		var urlValue = '../../role/getRoleByRoleId.ajax';
		if (updateCase != null && updateCase == "new") {
			document.getElementById("updateNew").value = "new";
			urlValue = '../../role/getRoleCaseByRoleId.ajax';
		} else {
			$("#tabs-9").css("display", "none");
		}
		var caseStatus = $.getUrlParam('caseStatus');
		if (caseStatus != null) {
			if (caseStatus == "UR" || caseStatus == "IR") {
				var lastRoleCaseId = $.getUrlParam('lastRoleCaseId');
				newRoleId = lastRoleCaseId;
			}
		}

		var menuUrl = '../../role/getAllMenuTreeNodesForEdit.ajax?roleId='
				+ newRoleId;
		if (updateCase != null && updateCase == "new") {
			menuUrl = '../../role/getAllMenuTreeNodesCaseForEdit.ajax?roleId='
					+ newRoleId;
		}

		InitTreeData(newRoleId, menuUrl);
		var permissionUrl = '../../role/getPermissionByRoleId.ajax';
		if (updateCase != null && updateCase == "new") {
			permissionUrl = '../../role/getPermissionByRoleCaseId.ajax';
		}
		getPermissionAll(newRoleId, permissionUrl);
		$.ajax({
			url : urlValue,
			type : 'get',
			dataType : 'JSON',
			cache : false,
			data : {
				roleId : roleId
			},
			success : function(data) {
				init_view(data);
			}
		});

	});

	function InitTreeData(roleId, menuUrl) {
		$('#roleMenuTree').tree({
			url : menuUrl,
			checkbox : true,
			cache : false,
			onCheck : function(node) {
			},
			onContextMenu : function(e, node) {
				e.preventDefault();
				$('#roleMenuTree').tree('select', node.target);
			}
		});
	}
	function getPermissionAll(roleId, permissionUrl) {
		$.ajax({
			url : '../../role/getPermissionAll.ajax',
			type : 'get',
			dataType : 'JSON',
			cache : false,
			success : function(data) {
				$('#permission_list').datagrid('loadData', data);

				$.ajax({
					url : permissionUrl,
					type : 'get',
					dataType : 'JSON',
					cache : false,
					data : {
						roleId : roleId
					},
					success : function(data) {
						var rows = $('#permission_list').datagrid('getRows');
						for (var i = 0; i < rows.length; i++) {
							for (var j = 0; j < data.length; j++) {
								if (rows[i].id == data[j].id) {
									$('#permission_list').datagrid('checkRow',
											i);
								}
							}
						}
					}
				});
			}
		});
	}

	function init_view(data) {
		if (data == null) {
			$.messager.alert('Error', '该数据已经关闭', 'error');
		}
		var id = data.realId;
		if (data.realId == null || data.realId == "null") {
			id = "";
		}
		$("#id").attr("value", id);
		$("#roleName").attr("value", data.name);
		$('#status').combobox("select", data.status);
		$("#desc").text(data.desc);
		$("#caseJudgment").text(data.caseJudgment);
	}
</script>
</head>
<body>
	<input type="hidden" name="updateNew" id="updateNew" value="old">
	<input type="hidden" name="realId" id="realId" value="">
	<input type="hidden" name="caseStatus" id="caseStatus" value="">
	<form id="new_form" method="post">
		<table class="table_view">
			<tr>
				<td class="td_view_subtitle" colspan="4">基本信息</td>
			</tr>
			<tr>
				<td class="td_new_name">角色编号</td>
				<td class="td_new_value"><input class="input_140" type="text"
					data-options="required:true" id="id" name="id" readonly="readonly"></td>
			</tr>
			<tr>
				<td class="td_new_name">角色名称</td>
				<td class="td_new_value"><input
					class="easyui-validatebox input_140" type="text"
					data-options="required:true" id="roleName" name="roleName"
					readonly="readonly"></td>
			</tr>
			<tr>
				<td class="td_new_name">状态</td>
				<td class="td_new_value"><select id="status"
					class="easyui-combobox" data-options="panelHeight:'auto'"
					editable="false" name="status" readonly="readonly"
					style="width: 140px;">
						<option value="O">正常</option>
						<option value="C">关闭</option>
				</select></td>
			</tr>
			<tr>
				<td class="td_new_name">角色菜单</td>
				<td style="height: 0px;">
					<ul id="roleMenuTree" data-options="" readonly="readonly"></ul>
				</td>
			</tr>
			<tr>
				<td class="td_view_name">权限</td>
				<td class="td_view_add">
					<table class="easyui-datagrid" title="角色列表" id="permission_list"
						readonly="readonly" style=""
						data-options="singleSelect:false,pagination:false,rownumbers:false">
						<thead>
							<tr>
								<th field="ck" checkbox="true"></th>
								<th data-options="field:'id',width:60" align="center">权限编号</th>
								<th data-options="field:'name',width:120">权限名称</th>
								<th data-options="field:'code',width:150">权限编码</th>
								<th data-options="field:'urlFilter',width:600">URL过滤</th>
							</tr>
						</thead>
					</table>
				</td>
			</tr>
			<tr>
				<td class="td_new_name">备注</td>
				<td class="tree-root-first"><textarea class="textarea_360"
						id="desc" name="desc"></textarea></td>
			</tr>
		</table>
	</form>

	<div id="tabs-9">
		<table class="table_view">
			<tr>
				<td class="td_view_name">意见：</td>
				<td class="tree-root-first"><textarea name="caseJudgment"
						id="caseJudgment" style="height: 60px;" cols="105"
						class="easyui-validatebox" readonly></textarea></td>
			</tr>
		</table>
	</div>
</body>
</html>